<!doctype html>
<%@page import="com.cn.ccp.util.Contants"%>
<jsp:directive.page import="com.cn.ccp.bean.UserBean" />
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<html>
<f:view>
<f:loadBundle var="messages" basename="messages"></f:loadBundle>
<head>
<meta charset="utf-8">
<title><h:outputText value="#{messages['system_title']}" /></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- styles -->
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/css/bootstrap-responsive.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/css/custom.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="../../js/html5.js"></script>
    <![endif]-->
    <!-- Fav and touch icons -->
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="<%=request.getContextPath()%>/images/icon/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="<%=request.getContextPath()%>/images/icon/favicon.png">
<link href="<%=request.getContextPath()%>/css/upload/default.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/upload/uploadify.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/upload/swfobject.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/upload/jquery.uploadify.v2.0.1.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"></script>
    <%
    int uid = 0 ;
    String imageType = (String)session.getAttribute(Contants.FILE_TYPE_IMAGE);
		UserBean users = (UserBean) session.getAttribute("userBean");
			if ((users == null) || (users.getUserName().equals(""))) {
	%>
		<jsp:forward page="../../sessionInvalid.jsp" />
	<%
	}else{
		uid = users.getId();
	}
	%>
	<%
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	%>
	<script type="text/javascript">
	var imageType = '*.xls' ;
		var uploadFileName = "";
		function insertTitle(tValue){ 
			exts = tValue.split(".");
			if(exts.length < 1){
				alert("错误，请上传正确的文件");
				return ;
			}
			ext = exts[1].toUpperCase();
			imageLayout = document.getElementById("imagelayoutId").value.toUpperCase() ;
			if(imageLayout.indexOf(ext) == -1){
				alert("错误，请上传正确的文件格式");
				return ;
			}
			uploadFileName = tValue ;
		} 
		function uploadFormSubmit(){
			if(uploadFileName == ''){
				return false;
			}
			return true ;
		}
		var isAllowSubmit = true ;
		function formSubmit(){
			if(!isAllowSubmit){
				alert("文件正在上传，请稍后提交。");
				return false;
			}	
		}
		$(document).ready(function() {
			$("#uploadify").uploadify({
				'uploader'       : '<%=request.getContextPath()%>/flexpaper/uploadify.swf',
				'script'         : '<%=basePath%>/servlet/UploadStudents?uid='+<%=uid%>,
				'cancelImg'      : '<%=request.getContextPath()%>/images/cancel.png',
				'folder'         : 'uploads',
				'queueID'        : 'fileQueue',
				'auto'           : true,
				'multi'          : false,
				'simUploadLimit' : 1,
				'buttonText'	 : 'upload' ,
				'fileDesc'       : '支持格式:'+imageType, //如果配置了以下的'fileExt'属性，那么这个属性是必须的  
                'fileExt'        : imageType,//允许的格式 
				'onComplete': function (event, queueID, fileObj, response, data) { 
					isAllowSubmit = true ;
					//$("#formid:imageError").val(response);
					if("success" != response){
						alert(response);
					}else{
						$("#courseImageId").show();
						document.getElementById("courseImageId").innerHTML = "学生信息上传成功" ;
					}
                },  
                'onError': function(event, queueID, fileObj) {  
                	isAllowSubmit = true ;
                    $("#formid:imageError").val("上传文件失败");
					$("#courseImageId").show();
                },  
                'onCancel': function(event, queueID, fileObj){  
                	isAllowSubmit = true ;
        			$("#courseImageId").show();
                } ,
                'onSelect': function(event, queueID, fileObj){  
                	isAllowSubmit = false ;
        			$("#courseImageId").hide();
                }  
			});
			var image = document.getElementById("formid:hiddenImagePath").value;
			if(image != ''){
				var url = "../../tempfile/"+image ;
				document.getElementById("courseImageId").innerHTML = "<img src=" + url + " height='156px' width='196px' />";
			}
   			$("#courseImageId").show();
		});
	</script>
</head>

<body class="bg-white" style="overflow-x:hidden;">  
<a id="viewDiv"></a>
	<h:form id="formid" styleClass="form-horizontal"
			style="margin-left: 20px;margin-right: 20px">
		<div class="row page-head">
			<h3 class="page-title">
				<i class="n-icon-selection  n-icon-black"></i><h:outputText value="#{messages['user_page_tile_student_tile']}"/>&nbsp;&gt;&nbsp;<b><h:outputText value="#{messages['user_page_tile_student_inport']}" /></b>
			</h3>
		</div>
		<h:inputHidden id="uploadStudent" value=""></h:inputHidden>
		<h:inputHidden value="#{studentAction.userBean.id}"></h:inputHidden>
		<fieldset>
				<legend>基本信息</legend>
				<div class="form-white">
					<!-- 
					<div class="control-group">
						<label class="control-label" for=""><h:outputText value="#{messages['faculty_page_label_faculty_name']}" /></label>
						<div class="controls">
							<h:selectOneMenu id="faculty" value="#{studentAction.userBean.facultyId}">
								<f:selectItem itemLabel="#{messages['messages_select']}" itemValue="-1" />
								<f:selectItems value="#{studentAction.facultySelectItem}" />
								<a4j:support event="onchange" action="#{studentAction.facultyChange}" reRender="specialty,grade"></a4j:support>
							</h:selectOneMenu>
							<span class="help-inline"><h:message for="faculty" style="color:red" /></span>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label" for=""><h:outputText value="#{messages['specialty_page_label_name']}" /></label>
						<div class="controls">
							<h:selectOneMenu id="specialty" value="#{studentAction.userBean.specialtyId}" >
								<f:selectItem itemLabel="#{messages['messages_select']}" itemValue="-1" />
								<f:selectItems value="#{studentAction.specialtySelectItem}" />
								<a4j:support event="onchange" action="#{studentAction.specialtyChange}" reRender="grade"></a4j:support>
							</h:selectOneMenu>
							<span class="help-inline"><h:message for="specialty" style="color:red" /></span>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label" for=""><h:outputText value="#{messages['user_page_label_grade']}" /></label>
						<div class="controls">
							<h:selectOneMenu id="grade" value="#{studentAction.userBean.grade}" >
								<f:selectItem itemLabel="#{messages['messages_select']}" itemValue="-1" />
								<f:selectItems value="#{studentAction.gradeSelectItem}" />
								<a4j:support event="onchange" action="#{studentAction.imageClick}" ></a4j:support>
							</h:selectOneMenu>
							<span class="help-inline"><h:message for="grade" style="color:red" /></span>
						</div>
					</div>
					  -->
					<div class="control-group">
						<label class="control-label" for=""><h:outputText value="#{messages['user_page_tile_student_inport_file']}" /></label>
						<div class="controls">
							<input type="file" name="uploadify" id="uploadify"  />
							<span class="help-inline"><h:outputText></h:outputText></span>
						</div>
					</div>
					<div class="control-group" id="showFileId">
						<label class="control-label" for=""><h:outputText id="image" value=""></h:outputText></label>
						<div class="controls">
							<div id="fileQueue" style="height: 60px "></div>
							<span class="help-inline"><h:message for="uploadStudent" style="color:red" /></span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for=""><h:outputText id="image" value=""></h:outputText></label>
						<div class="controls">
							<div id="courseImageId"></div>
							<span class="help-inline"><h:outputText id="imageError"></h:outputText></span>
						</div>
					</div>
					
				</div>
			</fieldset>
		<div class="form-actions">
			<h:commandButton value="#{messages['btn_submit']}" styleClass="btn btn-primary" action="#{studentAction.doInportStudents}"  onclick="return formSubmit();"/>
			<h:outputText value=" "></h:outputText>
			<a4j:commandButton value="#{messages['btn_cancel']}" action="main" styleClass="btn" immediate="true"/>
		</div>
	</h:form>
	<script src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			//document.getElementById('viewDiv').scrollIntoView();
		});
	</script>
</body>
</f:view>
</html>
